<?php
// this is another example showing how the dPFramework is working
// additionally we will have an easy database connection here

// as we are now within the tab box, we have to state (call) the needed information saved in the variables of the parent function
GLOBAL $AppUI, $canRead, $canEdit;

if (!$canRead) {			// lock out users that do not have at least readPermission on this module
	$AppUI->redirect( "m=public&a=access_denied" );
}
//prepare an html table with a head section
?>
<?php
// retrieving some dynamic content using an easy database query
$sql = "select i.trans_id, i.trans_code, i.trans_name, concat(contact_first_name, ' ', contact_last_name) as contact_name " .
	"   from transportations i " .
	"		left join users u on i.trans_resource = u.user_id " .
	"		left join contacts c on u.user_contact = c.contact_id ";
//$sql = "SELECT i.*, t.name as type_name FROM transportations i left join md_type t on type_id = item_type1 ";	// prepare the sqlQuery command to get all quotes from the einstein table
if (isset($_POST['searchterm']) && $_POST['searchterm'] != '') {
	$sql .= "where trans_code REGEXP '" . $_POST['searchterm'] . "'" .
			"	or concat(contact_first_name, ' ', contact_last_name) REGEXP '" . $_POST['searchterm'] . "'";
}
// pass the query to the database, please consider always using the (still poor) database abstraction layer
$quotes = db_loadList( $sql );		// retrieve a list (in form of an indexed array) of einstein quotes via an abstract db method
if ($quotes && is_array($quotes)) {
	echo json_encode($quotes);
}
else {
	echo '';
}
?>
